package cn.edu.ujn.booksshop.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.edu.ujn.booksshop.dao.Book;
import cn.edu.ujn.booksshop.dao.BookMapper;
import cn.edu.ujn.util.Page;

@Service
@Transactional
public class BookServiceImpl implements IBookService {

	@Autowired
	private BookMapper bookDao;

	@Override
	public Page<Book> selectAll(Integer page, Integer rows) {
		List<Book> list = this.bookDao.selectAll((page - 1) * rows, rows);
		Page<Book> pages = new Page<Book>();
		pages.setPage(page);
		pages.setRows(list);
		pages.setSize(rows);
		Integer count = this.bookDao.selectCount();
		pages.setTotal(count);
		return pages;
	}

	@Override
	public Integer selectCount() {
		Integer selectCount = this.bookDao.selectCount();
		return selectCount;
	}

	@Override
	public int deleteByPrimaryKey(Integer id) {
		int key = this.bookDao.deleteByPrimaryKey(id);
		return key;
	}

	@Override
	public int insertSelective(Book row) {
		int insert = this.bookDao.insert(row);
		return insert;
	}

	@Override
	public int updateByPrimaryKeySelective(Book bookDao) {
		int selective = this.bookDao.updateByPrimaryKeySelective(bookDao);
		return selective;
	}

	@Override
	public Book selectByPrimaryKey(Integer bookid) {
		Book bookById = this.bookDao.selectByPrimaryKey(bookid);
		return bookById;
	}

}
